<?php
require_once '../classes/class.relatorios.php';
require_once '../classes/class.IO.php';
require_once '../classes/class.funcoes.php';

$ClsRel = new Relatorios();
$ClsFunc = new Funcoes();

$cAno = $_POST['cAno'];

$cIO = new IO();
$cIO->Erase_Files("../temp");

$TotAln = $ClsRel->ReportTotalAlunos($cAno);

if(is_resource($TotAln))
    if(mysql_num_rows($TotAln) > 0)
    {
        require_once '../tfpdf.php';
        $pdf = new tFPDF();
        $pdf->Open();
        $pdf->AddPage();

        $pdf->SetFont('Arial', 'B', 10);
        
        $relData = date("Y-m-d");
        $RelCaption = "Relatório de Totalização de Alunos Anual";
       
        $pdf->Cell(0, 30, utf8_decode($RelCaption), 0, 0, 'C');
        $pdf->ln();
        $pdf->Cell(30, 5, utf8_decode('Data: ') . $relData , 0, 0, 'L');
        $pdf->ln();

        $pdf->SetFont('Arial', 'B', 10);
        $pdf->Cell(45, 5, utf8_decode('Curso'), 1);
        $pdf->Cell(45, 5, utf8_decode('Turma'), 1);
        $pdf->Cell(15, 5, utf8_decode('Mês'), 1);
        $pdf->Cell(15, 5, utf8_decode('Alunos'), 1, 0, "R");

        $pdf->SetFont('Arial', '', 10);
        $TotalAlunos = 0;
        while ($resultado = mysql_fetch_array($TotAln))
        {
                $pdf->ln();
                $pdf->Cell(45, 5, utf8_decode($resultado['Curso']), 1);
                $pdf->Cell(45, 5, utf8_decode($resultado['Turma']), 1);
                $pdf->Cell(15, 5,  utf8_decode($ClsFunc->RetornaMes($resultado['MES'], false)) , 1, 0 , "C");
                $pdf->Cell(15, 5, utf8_decode($resultado['Alunos']), 1, 0, "R");
                $TotalAlunos += $resultado['Alunos'];
        }
        $pdf->ln();
        $pdf->SetFont('Arial', 'I', 10);
        $pdf->SetFillColor(190, 190, 190);
        $pdf->Cell(105, 5, utf8_decode('Total de Alunos: '), 1, 0, "R", true);
        $pdf->Cell(15, 5, utf8_decode($TotalAlunos), 1, 0, "R", true ); 
        $DateNow = date('dmY_His');
        
        $namefill = "../temp/". $DateNow . ".pdf";
        $pdf->Output($namefill, "F");
        echo "temp/" . $DateNow . ".pdf";
    }
?>
